package com.lzy.mall.member.controller;


import cn.hutool.core.collection.CollUtil;
import com.lzy.mall.common.utils.PageUtils;
import com.lzy.mall.common.utils.ResultUtils;
import com.lzy.mall.member.entity.UmsMemberLevel;
import com.lzy.mall.member.service.UmsMemberLevelService;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * 会员等级(UmsMemberLevel)表控制层
 *
 * @author lzy
 * @since 2021-08-25 11:38:50
 */
@RestController
@RequestMapping("memberlevel")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class UmsMemberLevelController {
    private final UmsMemberLevelService memberLevelService;

    @GetMapping("/list")
    public ResultUtils list(@RequestParam Map<String, Object> params){
        PageUtils page = memberLevelService.queryPage(params);

        return ResultUtils.ok().put("page", page);
    }

    @GetMapping("/info/{id}")
    public ResultUtils info(@PathVariable("id") Long id){
        UmsMemberLevel memberLevel = memberLevelService.info(id);
        return ResultUtils.ok().put("memberLevel",memberLevel);
    }

    @PostMapping("/save")
    public ResultUtils save(@RequestBody UmsMemberLevel memberLevel){
        memberLevelService.save(memberLevel);
        return ResultUtils.ok();
    }

    @PostMapping("/update")
    public ResultUtils update(@RequestBody UmsMemberLevel memberLevel){
        memberLevelService.update(memberLevel);
        return ResultUtils.ok();
    }

    @PostMapping("/delete")
    public ResultUtils delete(@RequestBody Long[] levelIds){
        memberLevelService.removeBath(CollUtil.toList(levelIds));
        return ResultUtils.ok();
    }
}
